(function($){
    $.fn.imgCenter = function(options){
        this.each(function(){
            var _this = $(this),
                imgBoxWidth =_this.width(),
                imgBoxHeight =_this.height(),
                $img = _this.find('img');
                _this.css({'border':'1px solid #ddd','box-sizing':'border-box'});
            var imgObj = new Image();
            imgObj.onload = function(){
                var	imgWidth = this.width,
                    imgHeight = this.height;
                a = imgWidth/imgHeight;
                b = imgBoxWidth/imgBoxHeight;
                if((a/b)>=1){
                    $img.css('width',"100%");
                    $img.css('height',"auto");
                    var height = imgBoxWidth*(1/a);
                    imgHeight = height;
                    $img.css('margin-top',(imgBoxHeight-height)/2);
                } else{
                    $img.css('height',"100%");
                    $img.css('width',"auto");
                    var width = $img.height()*a;
                    $img.width(width);
                    $img.css({'display':"block",'margin':"auto"});
                }
            };
            imgObj.src = $img.attr("src");
        });
    }
})(jQuery);